package com.cong.security.core.code.sms;

import com.cong.security.core.code.ValidateCode;
import com.cong.security.core.code.ValidateCodeGenerator;
import com.cong.security.core.properties.SecurityProperties;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("smsCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

	@Autowired
	private SecurityProperties securityProperties;

	@Override
	public ValidateCode generate() {
		// 随机数字
		String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
		ValidateCode validateCode = new ValidateCode(code);
		return validateCode;
	}
}
